package jiyun.com.yiyanmeng;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList;

import adapter.AllAdaper;
import adapter.AllsAdaper;
import base.BaseFragment;
import bean.AllBean;
import presenter.AllPresenter;
import view.AllView;

/**
 * Created by 裘翔 on 2019/11/6.
 */

public class AllFragment extends BaseFragment<AllView, AllPresenter> implements AllView {
    private View view;
    private RecyclerView mAllRec;
    private SmartRefreshLayout mAllSmc;
    public int start = 0;
    public int end = 0;
    private ArrayList<AllBean.ShopBean> list;
    private AllAdaper allAdaper;
    private int page = 1;
    private RecyclerView mAllRecs;
    private ArrayList<AllBean.CourseBean> beans;
    private AllsAdaper allsAdaper;

    @Override
    protected AllPresenter bindPresenter() {
        return new AllPresenter();
    }

    @Override
    protected void initData() {
        mPresenter.loadData(start, end);
    }

    @Override
    protected void initListener() {

    }

    public void initView(View view) {
        mAllRec = (RecyclerView) view.findViewById(R.id.all_rec);
     //   mAllSmc = (SmartRefreshLayout) view.findViewById(R.id.all_smc);
        mAllRec.setLayoutManager(new LinearLayoutManager(getContext()));
        list = new ArrayList<>();
        allAdaper = new AllAdaper(getContext(), list);
        mAllRec.setAdapter(allAdaper);

//        mAllSmc.setOnLoadMoreListener(new OnRefreshLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshLayout) {
////                page++;
////                initData();
////                allAdaper.notifyDataSetChanged();
////                mAllSmc.finishLoadMore();
//            }
//
//            @Override
//            public void onRefresh(RefreshLayout refreshLayout) {
//                start = 0;
//                end = 0;
//                page = 0;
//                initData();
//                allAdaper.notifyDataSetChanged();
//                mAllSmc.finishRefresh();
//            }
//        });
//        mAllRecs = (RecyclerView) view.findViewById(R.id.all_recs);
//        mAllRecs.setLayoutManager(new LinearLayoutManager(getContext()));
//        beans = new ArrayList<>();
//        allsAdaper = new AllsAdaper(getContext(), beans);
//        mAllRecs.setAdapter(allsAdaper);
    }

    @Override
    protected int bindLayout() {
        return R.layout.all_fragment;
    }

    @Override
    public void showToast(String msg) {

    }

    @Override
    public void onSuccess(AllBean allBean) {
        list.addAll(allBean.getShop());
        allAdaper.notifyDataSetChanged();
//        beans.addAll(allBean.getCourse());
//        allsAdaper.notifyDataSetChanged();
    }

    @Override
    public void onFailed(String str) {

    }
}
